package com.lqs.sofp.servlet;

import com.lqs.sofp.service.UserService;
import com.lqs.sofp.service.impl.UserServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * @author cj
 */
@WebServlet(name = "UserRegisterServlet", value = "/User/register")
public class UserRegisterServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String phone = request.getParameter("phone");
        String gender = request.getParameter("gender");


        UserService userRegister = new UserServiceImpl();
        Boolean success = userRegister.register(username, password, phone, gender);


        if (success) {
            //注册成功
            response.sendRedirect(request.getContextPath());
        } else {
            //注册不成功则重新刷新注册页面
            response.sendRedirect(request.getContextPath() + "/register.html");
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
